<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="app">
        姓：<input type="text" v-model="firstName">
        名：<input type="text" v-model="lastName">
        全名：{{allName}}
        <br>
        <button @click="changeName">点击改名为李四</button>
        <h2>改后的名字为：{{allName}}</h2>
    </div>
    <script>
        const VM = new Vue({
            el:'#app',
            data:{
                firstName:'',
                lastName:''
            },
            computed:{
                allName:{
                    get(){

                        return this.firstName + '-' + this.lastName
                    },
                    set(v){
                        let arr = v.split('-');
                        this.firstName = arr[0];
                        this.lastName = arr[1];
                    }
                }
            },
            methods: {
                changeName(){
                    this.allName = '李-四'
                }
            },
        });
    </script>
</body>
</html>